package cn.iocoder.yudao.module.member.dal.mysql.memberconf.confpoint;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.confpoint.vo.MemberConfPointPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.memberconf.confpoint.MemberConfPointDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 积分奖励规则 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface MemberConfPointMapper extends BaseMapperX<MemberConfPointDO> {

    default PageResult<MemberConfPointDO> selectPage(MemberConfPointPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberConfPointDO>()
                .eqIfPresent(MemberConfPointDO::getTransactionType, reqVO.getTransactionType())
                .eqIfPresent(MemberConfPointDO::getMetalType, reqVO.getMetalType())
                .eqIfPresent(MemberConfPointDO::getPerUnit, reqVO.getPerUnit())
                .eqIfPresent(MemberConfPointDO::getPerType, reqVO.getPerType())
                .eqIfPresent(MemberConfPointDO::getPoints, reqVO.getPoints())
                .orderByDesc(MemberConfPointDO::getId));
    }

    default List<MemberConfPointDO> selectListByMaterialPolicyId(Long materialPolicyId) {
        return selectList(MemberConfPointDO::getMaterialPolicyId, materialPolicyId);
    }

    default List<MemberConfPointDO> selectListByMaterialPolicyIds(List<Long> materialPolicyIds) {
        return selectList(new LambdaQueryWrapperX<MemberConfPointDO>()
                .in(MemberConfPointDO::getMaterialPolicyId, materialPolicyIds));
    }

    default int deleteByMaterialPolicyId(Long materialPolicyId) {
        return delete(MemberConfPointDO::getMaterialPolicyId, materialPolicyId);
    }

}